<?php
/**
 * Created by PhpStorm.
 * User: songdewei
 * Date: 2017/10/12
 * Time: 下午4:10
 */

namespace Data\Company;


use Core\Model;
use Data\Company\Builder\CompanyContentBuilder;

class CompanyModel extends Model
{
    protected $table = 'company';

    /**
     * @param CompanyContentBuilder $object
     * @return bool|int|\mysqli_result|string
     * @throws \Exception
     */
    public function addObject(CompanyContentBuilder $object){
        if (!$object->getCompany_name()) {
            throw new \Exception('Empty company_name value');
        }

        if (!$object->getCompany_logo()) {
            throw new \Exception('Empty company_logo value');
        }

        if (!$object->getCreate_time()){
            $object->setCreate_time(time());
        }
        return $this->data($object->getBizContent())->add();
    }

    /**
     * @return CompanyContentBuilder
     */
    public function getObject(){
        $data = $this->getOne();
        return new CompanyContentBuilder($data);
    }

    /**
     * @param $company_id
     */
    public function deleteAllData($company_id){
        $this->where(array('company_id'=>$company_id))->delete();
        (new CompanyContentModel())->where(array('company_id'=>$company_id))->delete();
    }
}